import request from '@/services/request'

export type MyResponse = {
  code?: number
  msg?: string
  data?: any
}

/**
 * 获取单个用户所有订单
 * @param userId number
 * @returns
 */
export const getOrderList = (userId: number) => {
  return request.get('/order/getOrderByUserId', {
    userId,
  })
}

/**
 * 条件查询订单（待支付，已支付）
 */
export const getOrderByKey = (status: number) => {
  return request.get('/userkey/order/getOrder', {
    status,
  })
}

export type addOrderParams = {
  goodsId: number
  goodsNumber: number
}
/**
 * 新增订单
 * @param data addOrderParams
 * @returns
 */
export const addOrder = (data: addOrderParams) => {
  return request.post('/order/api/v1/order/add', data)
}

/**
 * 根据订单id获取订单详情（数量，支付金额等）
 * @param orderId
 * @returns
 */
export const getSingleOrderInfoByID = (orderId: string) => {
  return request.get('/order/api/v1/order/getOrderById', { orderId })
}

type updateOrderStatusParams = {
  orderId: number
  status: number
}
/**
 * 订单状态转换
 * @param data updateOrderStatusParams
 * @returns
 */
export const updateOrderStatus = (data: updateOrderStatusParams) => {
  return request.post('/userkey/order/updateStatus', data)
}

interface payOrderParams {
  orderId: string
  goodsId: number
  payMethod: string
}
/**
 * 支付订单
 * @param data
 * @returns
 */
export const payOrder = (data: payOrderParams) => {
  return request.post('/order/api/v1/order/pay', data)
}

/**
 * 用户查看自己的所有订单
 */
export const getMyAllOrderList = () => {
  return request.get('/order/api/v1/order/getMyOrder')
}

/**
 * 用户获取所有分类
 */

export const getAllCategory = () => {
  return request.get('/user/api/v1/channel/getChannel')
}

/**
 * 用户获取分页商品信息
 */
export interface getHomeProductListParams {
  channelId?: number
  page: number
  pageSize: number
  [property: string]: any
}
export const getHomeProductList = (data: getHomeProductListParams) => {
  return request.get('/user/api/v1/product/page', data)
}

/**
 * 用户获取热点商品（轮播图）
 */
export const getHotGoodList = () => {
  return request.get('/user/api/v1/product/hot')
}

/**
 * 用户根据Id查询商品详情
 */
export interface getGoodDetailParams {
  id: number
  [property: string]: any
}

export const getGoodDetail = (id: number) => {
  return request.get(`/user/api/v1/product/${id}`)
}

/**
 * 用户取消订单(需要带query参数，请求拦截器实现不了，组件内部直接调用)
 */
// type cancelOrderParams = { orderId: string; goodsId: number }
// export const cancelOrder = (data: cancelOrderParams) => {
//   return request.put('/order/api/v1/order/cancel', data)
// }

/**
 * 用户删除订单
 */
export interface delOrderParams {
  goodsId?: number
  orderId?: string
  [property: string]: any
}

export const delOrder = (data: delOrderParams) => {
  return request.delete('/order/api/v1/order/deleteById', data)
}
